﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Jingxing.Models.Admin
{
    public class BaseModel
    {
        public bool IsReturn { get; set; }
        public string NewLink { get; set; }
        public List<Menu> MenuList { get; set; }
        public string Caption { get; set; }
        public Menu GetSelectMenu()
        {
            foreach (var menu in MenuList)
            {
                if (menu.IsSelect)
                    return menu;
            }
            return null;
        }

        public BaseModel()
        {
            MenuList = new List<Menu>() 
            {
                 new Menu(){ Title = "主页管理" , Key = "" , SubList = new List<Menu>()
                {
                    new Menu(){ Title = "广告大图" , Key = "/Admin/Banner"},
                    new Menu(){ Title = "其他设置" , Key = "/Admin/OtherSetting"},
                }},
                new Menu(){ Title = "页面管理" , Key = "", SubList = new List<Menu>()
                {
                    new Menu(){ Title = "公司简介" , Key = "/Admin/Title?type=Introduction"},
                    new Menu(){ Title = "新闻中心" , Key = "/Admin/Title?type=News"},
                    new Menu(){ Title = "加盟连锁" , Key = "/Admin/Title?type=ChainStore"},
                    new Menu(){ Title = "产品项目" , Key = "/Admin/Title?type=Product"},
                    new Menu(){ Title = "汽车美容" , Key = "/Admin/Title?type=School"},
                    new Menu(){ Title = "直营店" , Key = "/Admin/Title?type=Store"},
                    new Menu(){ Title = "客服中心" , Key = "/Admin/Title?type=CallCenter"},
                    new Menu(){ Title = "俱乐部" , Key = "/Admin/Title?type=Club"},
                    new Menu(){ Title = "联系我们" , Key = "/Admin/Title?type=Contact"},
                    new Menu(){ Title = "养护常识" , Key = "/Admin/Title?type=Knowledge"},
                }},
                new Menu(){ Title = "留言管理" , Key = "", SubList = new List<Menu>()
                {
                    new Menu(){ Title = "留言管理" , Key = "/Admin/CommentMgt"},
                }}};
        }

        public void Select(string title)
        {
            foreach (var menu in MenuList)
            {
                menu.IsSelect = false;
                if (menu.Title == title)
                {
                    menu.IsSelect = true;
                    foreach (var subMenu in menu.SubList)
                    {
                        subMenu.IsSelect = false;
                    }
                }
                else
                {
                    foreach (var subMenu in menu.SubList)
                    {
                        subMenu.IsSelect = false;
                        if (subMenu.Title == title)
                        {
                            subMenu.IsSelect = true;
                            menu.IsSelect = true;
                        }
                    }
                }
            }
        }
    }
}